/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.dao;

import org.ipti.br.tag.entity.Deletes;
import org.ipti.br.tag.entity.Deletes_;
import java.util.Calendar;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

/**
 *
 * @author israel
 */
@Stateless
public class DeletesFacade extends AbstractFacade<Deletes> {

    @PersistenceContext(unitName = "TAG2PU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public DeletesFacade() {
        super(Deletes.class);
    }

    public List<Deletes> DeletesBetweenDate(Calendar initialDate, Calendar finalDate, Long serialNumber) {
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery<Deletes> cq = cb.createQuery(Deletes.class);
        Root<Deletes> from = cq.from(Deletes.class);
        Predicate predicate1 = cb.greaterThanOrEqualTo(from.get(Deletes_.occurredDate), initialDate);
        Predicate predicate2 = cb.lessThan(from.get(Deletes_.occurredDate), finalDate);
        Predicate predicate3 = cb.notEqual(from.get(Deletes_.serialNumber), serialNumber);
        cq.orderBy(cb.asc(from.get(Deletes_.id)));
        cq.where(cb.and(predicate1, predicate2, predicate3));

        return getEntityManager().createQuery(cq).getResultList();
    }
}
